/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dtn.wsn.demo;

import com.dtn.wsn.dao.TableManager;
import com.dtn.wsn.database.ConnectionPool;
import com.dtn.wsn.sunspot.SunspotConnectionManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * WSNApplication to manage the sunspot radio connection and
 * mysql database connection
 * 
 * @author hao
 */
public class WSNApplication {
    private SunspotConnectionManager scm;
    private ConnectionPool connPool;

    public ConnectionPool getConnectionPool() {
        return connPool;
    }

    public SunspotConnectionManager getSunspotConnectionManager() 
    {
        return scm;
    }
    /**
     * constructor with default port
     */
    public WSNApplication() 
    {
        this.scm = new SunspotConnectionManager();
        this.connPool = new ConnectionPool("com.mysql.jdbc.Driver",   
                "jdbc:mysql://localhost:3306/wsn", "root", "bytewalla5");   
        try {
            connPool.createPool();
        } catch (Exception ex) {
            Logger.getLogger(WSNApplication.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    /**
     * constructor with specific constructor
     * @param port 
     */
    public WSNApplication(int port) 
    {
        this.scm = new SunspotConnectionManager(port);
        this.connPool = new ConnectionPool("com.mysql.jdbc.Driver",   
                "jdbc:mysql://localhost:3306/wsn", "root", "bytewalla5");   
        try {
            connPool.createPool();
        } catch (Exception ex) {
            Logger.getLogger(WSNApplication.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    /**
     * tear down all the radio connection and database connections
     * 
     */
    public void TearDownWSNApplication()
    {
        try {
            this.connPool.closeConnectionPool();
     
            this.scm.tearDownRadiogramConnection();
           
        } catch (SQLException ex) {
            Logger.getLogger(WSNApplication.class.getName()).log(Level.SEVERE, null, ex);
        }catch (Exception ex) {
                Logger.getLogger(WSNApplication.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
   
  
    public static void main(String[] args) throws Exception 
    {  
        HttpSqsReceiverThread hsrt = new HttpSqsReceiverThread();
        Thread msglistner = new Thread(hsrt);
        msglistner.start();
        
    }
}
